package com.fy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fy.entity.Cop;
import com.fy.entity.Result;
import com.fy.entity.Search;
import com.fy.service.ICopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 晓岩
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/cop")
public class CopController {
    @Autowired
    ICopService copService;
    @RequestMapping("list")
    public Result list(@RequestBody Search search){
        QueryWrapper<Cop> wrapper = new QueryWrapper<>();
        if(search.getName()!=null&&!search.getName().equals("")){
            wrapper.like("name",search.getName());
        }
        if(search.getArea()>0){
            wrapper.eq("carea",search.getArea());
        }
        if(search.getScope()>0){
            wrapper.eq("cscope",search.getScope());
        }
        if(search.getDate1()!=null){
            wrapper.ge("time",search.getDate1());
        }
        if(search.getDate2()!=null){
            wrapper.le("time",search.getDate2());
        }
        Page page = new Page(search.getPage(),search.getPageSize());
        Page page1 = copService.page(page, wrapper);
        return new Result(200,"",page1);
    }
}
